import logging

import globals

def init_logging(opts):
    if opts.datefmt is None:
        logging.basicConfig(
                level=logging.DEBUG,
                format=opts.format
            )
    else:
        logging.basicConfig(
                level=logging.DEBUG,
                format=opts.format,
                datefmt=opts.datefmt
            )
    logger = logging.getLogger(globals.SCRIPT_NAME)
    #print opts.verbosity
    logger.setLevel(opts.verbosity)
    if opts.logfile is not None:
        file_logger = logging.FileHandler(opts.logfile)
        file_logger.setLevel(opts.verbosity)
        logger.addHandler(file_logger)
    return logger

